From bf805f7da68891250a10d85d9206607de3cbfacf Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 2 Sep 2024 13:24:07 +0700
Subject: <iman> temp save update fetch data promotion program line

---
 src/pages/shop/promo/[slug].tsx | 67 ++++++++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 18 deletions(-)

(limited to 'src/pages/shop/promo/[slug].tsx')

diff --git a/src/pages/shop/promo/[slug].tsx b/src/pages/shop/promo/[slug].tsx
index aaee1249..92f5b7f8 100644
--- a/src/pages/shop/promo/[slug].tsx
+++ b/src/pages/shop/promo/[slug].tsx
@@ -2,30 +2,31 @@ import dynamic from 'next/dynamic'
 import NextImage from 'next/image';
 import { useEffect, useState } from 'react'
 import { useRouter } from 'next/router'
-import Seo from '../../../core/components/Seo'
-import Promocrumb from '../../../lib/promo/components/Promocrumb'
-import { fetchPromoItemsSolr, fetchVariantSolr } from '../../../api/promoApi'
+import Seo from '../../../core/components/Seo.jsx'
+import Promocrumb from '../../../lib/promo/components/Promocrumb.jsx'
+import { fetchPromoItemsSolr, fetchVariantSolr } from '../../../api/promoApi.js'
 import LogoSpinner from '../../../core/components/elements/Spinner/LogoSpinner.jsx'
-import ProductPromoCard from '../../../../src-migrate/modules/product-promo/components/Card'
-import { IPromotion } from '../../../../src-migrate/types/promotion'
+import ProductPromoCard from '../../../../src-migrate/modules/product-promo/components/Card.tsx'
+import { IPromotion } from '../../../../src-migrate/types/promotion.ts'
 import React from 'react'
 import { SolrResponse } from "../../../../src-migrate/types/solr.ts";
-import DesktopView from '../../../core/components/views/DesktopView';
-import MobileView from '../../../core/components/views/MobileView';
+import DesktopView from '../../../core/components/views/DesktopView.jsx';
+import MobileView from '../../../core/components/views/MobileView.jsx';
 import 'swiper/swiper-bundle.css';
-import useDevice from '../../../core/hooks/useDevice'
-import ProductFilterDesktop from '../../../lib/product/components/ProductFilterDesktopPromotion';
-import ProductFilter from '../../../lib/product/components/ProductFilter';
+import useDevice from '../../../core/hooks/useDevice.js'
+import ProductFilterDesktop from '../../../lib/product/components/ProductFilterDesktopPromotion.jsx';
+import ProductFilter from '../../../lib/product/components/ProductFilter.jsx';
 import { HStack, Image, Tag, TagCloseButton, TagLabel } from '@chakra-ui/react';
-import { formatCurrency } from '../../../core/utils/formatValue';
-import Pagination from '../../../core/components/elements/Pagination/Pagination';
-import SideBanner from '../../../../src-migrate/modules/side-banner';
-import whatsappUrl from '../../../core/utils/whatsappUrl';
+import { formatCurrency } from '../../../core/utils/formatValue.js';
+import Pagination from '../../../core/components/elements/Pagination/Pagination.js';
+import SideBanner from '../../../../src-migrate/modules/side-banner/index.tsx';
+import whatsappUrl from '../../../core/utils/whatsappUrl.js';
 import { cons, toQuery } from 'lodash-contrib';
 import _ from 'lodash';
-import useActive from '../../../core/hooks/useActive';
+import useActive from '../../../core/hooks/useActive.js';
+import useProductSearch from '../../../lib/product/hooks/useProductSearch.js';
 
-const BasicLayout = dynamic(() => import('../../../core/components/layouts/BasicLayout'))
+const BasicLayout = dynamic(() => import('../../../core/components/layouts/BasicLayout.jsx'))
 
 export default function PromoDetail() {
   const router = useRouter()
@@ -40,9 +41,39 @@ export default function PromoDetail() {
   const [categories, setCategories] = useState<Category[]>([]);
   const [brandValues, setBrandValues] = useState<string[]>([]);
   const [categoryValues, setCategoryValues] = useState<string[]>([]);
-  const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular');
+  const [orderBy, setOrderBy] = useState(router.query?.orderBy);
   const popup = useActive();
   const prefixUrl = `/shop/promo/${slug}`
+  const [queryFinal, setQueryFinal] = useState({});
+  const [limit, setLimit] = useState<number>(30);
+  const [q, setQ] = useState('**');
+  const [finalQuery, setFinalQuery] = useState({fq: `type_value_s:${slug}`});
+  const [products, setProducts] = useState(null);
+  useEffect(() => {
+    setQueryFinal({ ...finalQuery, q, limit, orderBy });
+}, [router.query, prefixUrl, slug, brand, category, priceFrom, priceTo, currentPage]);
+  useEffect(() => {
+      setQueryFinal({ ...finalQuery, q, limit, orderBy });
+  }, [router.query, prefixUrl, slug, brand, category, priceFrom, priceTo, currentPage]);
+
+  const { productSearch } = useProductSearch({
+    query: queryFinal,
+    operation: 'OR',
+  });
+
+  console.log("productSearch",productSearch)
+  console.log("queryFinal",queryFinal)
+
+  const pageCount = Math.ceil(productSearch.data?.response.numFound / limit);
+  const productStart = productSearch.data?.responseHeader.params.start;
+  const productRows = limit;
+  const productFound = productSearch.data?.response.numFound;
+
+  useEffect(() => {
+    setProducts(productSearch.data?.response?.products);
+  }, [productSearch]);
+
+  console.log("products",products)
 
   useEffect(() => {
     if (router.query.brand) {
@@ -91,7 +122,7 @@ export default function PromoDetail() {
       setCurrentPage(pageNumber)
       
       try {
-        const items = await fetchPromoItemsSolr(`type_value_s:${Array.isArray(slug) ? slug[0] : slug}`,0,100);
+        const items = await fetchPromoItemsSolr(`type_value_s:${Array.isArray(slug) ? slug[0] : slug}`,0,10);
         setPromoItems(items);
         
         if (items.length === 0) {
-- 
cgit v1.2.3

